<template>
  <el-dialog :title="'审批配置'" :close-on-click-modal="false" :visible.sync="visible">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="环节名称" prop="detailsMc">
      </el-table-column>
     
      <el-table-column label="操作权限" prop="businessPemission">
      </el-table-column>
      <el-table-column label="审批人员" prop="examineUserName">
      </el-table-column>
       <el-table-column label="环节说明" maxlength="100" prop="detailsSm" show-overflow-tooltip>
      </el-table-column>
      <el-table-column align="right" width="350px">
        <template   slot="header" slot-scope="scope">
          <el-button @click="addParentNode()">新增根环节</el-button>
        </template>
        <template slot-scope="scope">
          <el-button type="primary" plain @click="handleAdd(scope.$index, scope.row)">添加</el-button>
           <el-button type="primary" plain @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <sysexaminedetails ref="sysexaminedetails" @refreshDataList="refreshDataList"></sysexaminedetails>
  </el-dialog>
</template>
<script>
  import {
    getByExamineId,
    delObj
  } from '@/api/admin/sysexaminedetails'
  import sysexaminedetails from './sysexaminedetails-form'
  export default {
    components: {
      sysexaminedetails
    },
    data() {
      return {
        visible: false,
        canSubmit: false,
        tableData: [],
        examineId: ''
      }
    },
    methods: {
      init(id) {
        this.visible = true;
        this.canSubmit = true;
        this.examineId = id;
        this.tableData = [];
        this.$nextTick(() => {
          getByExamineId(id).then(response => {
             this.tableData = response.data.data
          })
        })
      },
      refreshDataList() {
        getByExamineId(this.examineId).then(response => {
          this.tableData = response.data.data
        })
      },
 
      /**
       * 添加根节点
       */
      addParentNode() {
        this.$nextTick(() => {
          this.$refs.sysexaminedetails.init(this.examineId, null, 0);
        });
      },
      /**
       * 添加子节点
       */
      handleAdd(index, row) {
        this.$refs.sysexaminedetails.init(this.examineId, null, row.detailsId);
      },
      handleEdit(index,row){
         this.$refs.sysexaminedetails.init(null,  row.detailsId,null)
      },
      /**
       * 删除节点
       */
      handleDelete(index, row) {
           this.$confirm('确认删除该环节？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delObj(row.detailsId)
        }).then(data => {
          this.$message.success('删除成功')
         this.refreshDataList();
        })
      }
    }
  }

</script>
